TypeScript使用時のJavaScript Runtimeごとのimport時の拡張子の有無
前提
<JS Runtime> & ESM & TypeScriptの時の話
Node.js
かなり意味不明で厳しい
Bun
code:ts
import { hello } from "./hello";
import { hello } from "./hello.ts"; // this works
Deno
code:ts
import { add, multiply } from "./arithmetic.ts";
.tsの拡張子が必須
A package can consist of multiple modules. You can reference other modules in your package using relative imports. You should use the correct extensions in the imports – ./greet.ts to import the greet.ts, rather than ./greet or ./greet.js.ref ただし、package.jsonがあると拡張子を省略できる(?)
import時に拡張子を指定しなくても良いimportの仕方の呼称?
package.jsonがパッケージに含まれている場合、モジュールは「スロッピーインポート」を使用できます。「スロッピーインポート」では、拡張子なしでファイルをインポートしたり、基底ファイルが.tsであっても.js拡張子でインポートしたりできます。また、index.js解決でディレクトリインポートを使用することもできます。ref なんでこんな用語あるんだよぉmrsekut.icon
これまたよくわからない仕様
多くのruntimeをサポートできるように広い仕様になっているのだろうか?